Skip to content

test: replace PostgreSQL with CockroachDB in integration tests#896

Merged
AchoArnold merged 8 commits into
mainfrom
feat/cockroachdb-integration-tests
May 18, 2026
Merged

test: replace PostgreSQL with CockroachDB in integration tests#896
AchoArnold merged 8 commits into
mainfrom
feat/cockroachdb-integration-tests

Conversation

@AchoArnold
Copy link
Copy Markdown
Member

Replace PostgreSQL with CockroachDB in the integration test Docker Compose to match production.

Changes

  • tests/docker-compose.yml: cockroachdb/cockroach:latest (single-node, insecure, in-memory)
  • tests/.env.test: Updated DATABASE_URL for CockroachDB, enabled MIGRATION_CONSTRAINT_FIX
  • tests/README.md: Updated references from PostgreSQL to CockroachDB

Why

Production uses CockroachDB. This ensures tests exercise the same DB engine.

No application code changes needed (GORM postgres driver is wire-compatible).

AchoArnold and others added 5 commits May 18, 2026 09:54
Replace PostgreSQL with CockroachDB in the integration test Docker
Compose to match the production database environment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use cockroachdb/cockroach:latest in single-node insecure mode with in-memory storage. Add cockroachdb-init service to create the database and update the seed service to use cockroach sql CLI.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Point DATABASE_URL at cockroachdb:26257 with root user (insecure mode).
Enable DATABASE_MIGRATION_CONSTRAINT_FIX for CockroachDB compatibility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace all PostgreSQL references with CockroachDB in the architecture
diagram, components table, and troubleshooting section.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 18, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 18, 2026

Greptile Summary

This PR swaps the integration test database from postgres:alpine to cockroachdb/cockroach:latest in single-node insecure mode, aligning the test environment with production. It adds a one-shot cockroachdb-init service to create the database (required because CockroachDB has no POSTGRES_DB equivalent), updates connection strings, enables DATABASE_MIGRATION_CONSTRAINT_FIX, and refreshes the README.

  • tests/docker-compose.yml: Replaces the postgres service with CockroachDB (in-memory, single-node), adds a cockroachdb-init one-shot container for DB creation, and migrates the seed service from psql to cockroach sql.
  • tests/.env.test: Points DATABASE_URL / DATABASE_URL_DEDICATED at cockroachdb:26257 with root user and sslmode=disable; adds DATABASE_MIGRATION_CONSTRAINT_FIX=1 to enable the existing GORM DDL workaround.
  • docs/superpowers/: Adds agentic planning/spec documents that describe the implementation decisions.

Confidence Score: 4/5

Safe to merge — the changes are isolated to the test environment and do not touch any application code.

All three CockroachDB containers use the unversioned latest tag, which may drift from the production version over time and could pull a release with different SQL or migration behavior, subtly defeating the production-parity goal of this PR.

tests/docker-compose.yml — the latest image tag on all three CockroachDB containers is worth revisiting to pin to the production version.

Important Files Changed

Filename Overview
tests/docker-compose.yml Replaces postgres:alpine with CockroachDB single-node (in-memory); adds cockroachdb-init one-shot service for DB creation; updates seed and api dependencies. All structural changes look correct — only concern is use of the unversioned latest tag across all three CockroachDB containers.
tests/.env.test Updates DATABASE_URL/DATABASE_URL_DEDICATED to CockroachDB connection strings with root user and sslmode=disable; adds DATABASE_MIGRATION_CONSTRAINT_FIX=1 to enable the existing GORM migration workaround for CockroachDB.
tests/README.md Documentation-only update: replaces PostgreSQL references with CockroachDB in ASCII diagram, components table, and troubleshooting section.
docs/superpowers/plans/2026-05-18-cockroachdb-integration-tests.md New agentic planning document describing the implementation steps; functionally matches what was implemented. No code issues, but these planning artifacts are arguably unnecessary in the committed codebase.
docs/superpowers/specs/2026-05-18-cockroachdb-integration-tests-design.md New agentic design spec document; accurately documents the key decisions made. Same observation as the plans doc — planning artifacts with limited long-term value in the main branch.

Sequence Diagram

sequenceDiagram
    participant DC as Docker Compose
    participant CDB as cockroachdb (in-memory)
    participant INIT as cockroachdb-init (one-shot)
    participant API as api (Go)
    participant SEED as seed (one-shot)
    participant TR as Test Runner (go test)

    DC->>CDB: start (start-single-node --insecure)
    CDB-->>DC: "healthy (/health?ready=1)"
    DC->>INIT: start (depends_on: cockroachdb healthy)
    INIT->>CDB: CREATE DATABASE IF NOT EXISTS httpsms
    INIT-->>DC: exit 0 (service_completed_successfully)
    DC->>API: start (depends_on: cockroachdb-init completed)
    API->>CDB: GORM auto-migrate (DDL)
    API-->>DC: healthy (/health)
    DC->>SEED: start (depends_on: api healthy)
    SEED->>CDB: "cockroach sql --file=/seed.sql"
    SEED-->>DC: exit 0
    TR->>API: HTTP integration tests
    API->>CDB: queries
    CDB-->>API: results
    API-->>TR: responses
Loading

Reviews (1): Last reviewed commit: "docs: update integration test README for..." | Re-trigger Greptile

@AchoArnold AchoArnold requested a review from Copilot May 18, 2026 07:12
Comment thread tests/docker-compose.yml Outdated
Comment on lines +2 to +4
cockroachdb:
image: cockroachdb/cockroach:latest
command: start-single-node --insecure --store=type=mem,size=256MiB
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Using cockroachdb/cockroach:latest for all three CockroachDB containers (cockroachdb, cockroachdb-init, seed) undermines the stated goal of matching production. If production is pinned to a specific CockroachDB version, latest may pull a newer release with different SQL semantics, migration behavior, or serialization changes — making the test environment diverge from production in exactly the way this PR aims to fix.

Suggested change
cockroachdb:
image: cockroachdb/cockroach:latest
command: start-single-node --insecure --store=type=mem,size=256MiB
cockroachdb:
image: cockroachdb/cockroach:v24.3.4 # pin to the same version used in production
command: start-single-node --insecure --store=type=mem,size=256MiB

Comment on lines +1 to +5
# CockroachDB Integration Tests Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Replace PostgreSQL with CockroachDB in the integration test Docker Compose so the test environment matches production.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Agentic planning artifacts committed to the repository

These two files (docs/superpowers/plans/ and docs/superpowers/specs/) appear to be intermediate planning documents generated by an AI development workflow. Committing them adds permanent repository noise for content that has no value to future contributors — the implementation intent is better captured in the PR description and the resulting code. Consider whether these belong in .gitignore or a separate scratch branch rather than main.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

AchoArnold and others added 2 commits May 18, 2026 10:13
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The CockroachDB Docker image does not include curl. Use
'cockroach sql --execute=SELECT 1' for the healthcheck instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the integration test stack under tests/ to use CockroachDB instead of PostgreSQL, aligning the test environment’s database engine with production.

Changes:

  • Swapped the postgres service for a single-node cockroachdb service, plus a one-shot init container to create the httpsms database.
  • Updated test environment variables to point DATABASE_URL* at CockroachDB and enabled DATABASE_MIGRATION_CONSTRAINT_FIX.
  • Updated integration test documentation and added accompanying design/plan docs.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/docker-compose.yml Replaces PostgreSQL with CockroachDB, adds init step, updates API/seed dependencies accordingly.
tests/.env.test Updates DB connection strings for CockroachDB and enables migration compatibility flag.
tests/README.md Updates architecture diagram and text references from PostgreSQL to CockroachDB.
docs/superpowers/specs/2026-05-18-cockroachdb-integration-tests-design.md Adds design spec documenting the rationale and approach.
docs/superpowers/plans/2026-05-18-cockroachdb-integration-tests.md Adds implementation plan/checklist for the migration.

Comment thread tests/docker-compose.yml
Comment thread tests/docker-compose.yml Outdated
Comment on lines +2 to +4
cockroachdb:
image: cockroachdb/cockroach:latest
command: start-single-node --insecure --store=type=mem,size=256MiB
CockroachDB requires at least 640 MiB for in-memory storage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AchoArnold AchoArnold merged commit 2bc05d0 into main May 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants